'use strict'
/**
 * Alipay SDK
 * date 2017/11/01
 * author chen
 */
import { NativeModules, DeviceEventEmitter } from 'react-native';
//module.exports = NativeModules.Alipay;
const NativeAlipay = NativeModules.Alipay;

Object.assign(exports, NativeAlipay);

const regParse = /(\w+)=(.+)/;
function parseResult(str) {
  console.log(str);
  if (typeof(str) !== 'string') {
    return str;
  }
  const ret = {};
  str.split(',').forEach(v=>{
    const m = regParse.exec(v);
    console.log(m);
    if (m){
      ret[m[1]] = m[2];
      console.log(ret);
    }
  });
  return ret;
}

/*async*/ function pay(orderInfo) {
  return NativeAlipay.pay(orderInfo)
    .then(result=>parseResult(result));
};
exports.pay = pay;
